1 //+-----------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // Defines the PersistFile class of PresentationHost
12 // Ported Windows->DevDiv. See SourcesHistory.txt.
14 //------------------------------------------------------------------------
16 #include "Precompiled.hxx"
17 #include "PersistFile.hxx"
18 #include "HostShim.hxx"
19 #include "ShimUtilities.hxx"
21 //******************************************************************************
23 // CPersistFile::CPersistFile()
25 //******************************************************************************
27 CPersistFile::CPersistFile(__in CHostShim
* pHostShim
)
29 m_pHostShim
= pHostShim
;
32 //******************************************************************************
34 // CPersistFile::~CPersistFile()
36 //******************************************************************************
38 CPersistFile::~CPersistFile()
42 //******************************************************************************
44 // CPersistFile::QueryInterface()
46 //******************************************************************************
48 STDMETHODIMP
CPersistFile::QueryInterface(REFIID riid
, __out LPVOID
*ppReturn
)
50 return m_pHostShim
->QueryInterface(riid
, ppReturn
);
53 //******************************************************************************
55 // CPersistFile::AddRef()
57 //******************************************************************************
59 STDMETHODIMP_(ULONG
) CPersistFile::AddRef()
61 return m_pHostShim
->AddRef();
64 //******************************************************************************
66 // CPersistFile::Release()
68 //******************************************************************************
70 STDMETHODIMP_(ULONG
) CPersistFile::Release()
72 return m_pHostShim
->Release();
75 //******************************************************************************
77 // CPersistFile::GetClassID()
79 //******************************************************************************
81 STDMETHODIMP
CPersistFile::GetClassID(__out LPCLSID pClassID
)
83 return m_pHostShim
->GetClassID(pClassID
);
86 //******************************************************************************
88 // CPersistFile::Save()
90 //******************************************************************************
92 STDMETHODIMP
CPersistFile::Save(__in_ecount(MAX_PATH
+1) LPCOLESTR
, BOOL
)
94 // File->Save is enabled/disabled by IOleCommandTarget->QueryStatus like any other menu item
95 // However, once enabled it calls IPersistFile->Save rather than IOleCommandtarget->Exec.
96 // To make it work like the other menu items we simply turn around and call Exec ourselves.
98 IOleCommandTarget
* pCmdTarget
= NULL
;
99 CKHR(QueryInterface(IID_IOleCommandTarget
, (VOID
**)&pCmdTarget
));
100 CKHR(pCmdTarget
->Exec(NULL
, OLECMDID_SAVE
, NULL
, NULL
, NULL
));
103 ReleaseInterface(pCmdTarget
);
107 //******************************************************************************
109 // CPersistFile::SaveCompleted()
111 //******************************************************************************
113 STDMETHODIMP
CPersistFile::SaveCompleted(LPCOLESTR pwszFile
)
118 //******************************************************************************
120 // CPersistFile::Load()
122 // This method is called if file is local.
124 //******************************************************************************
126 STDMETHODIMP
CPersistFile::Load(__in_ecount(MAX_PATH
+ 1) LPCOLESTR pwszFile
, DWORD dwMode
)
130 MimeType mimeType
= MimeType_Unknown
;
132 EventWriteWpfHostUm_IPersistFileLoad(pwszFile
);
134 m_pHostShim
->SetActivationType(FileActivation
);
136 if (m_pHostShim
->GetAllowPersistFileLoad() == FALSE
&& m_pHostShim
->IsAllowPersistFileLoadSet())
145 m_pHostShim
->SetStartupUri(pwszFile
);
146 m_pHostShim
->SetLocalDeploymentManifestPath(pwszFile
);
148 const DWORD SZMIMESIZE_MAX
= 128;
149 WCHAR wzBuffer
[SZMIMESIZE_MAX
+ 1];
150 DWORD dwCharCount
= SZMIMESIZE_MAX
;
152 CKHR(AssocQueryString(
154 ASSOCSTR_CONTENTTYPE
, // ASSOCSTR str,
155 PathFindExtension(pwszFile
), // LPCTSTR pszAssoc,
156 0, // LPCTSTR pszExtra,
157 wzBuffer
, // LPTSTR pszOut,
158 &dwCharCount
// DWORD *pcchOut
161 mimeType
= GetMimeTypeFromString(wzBuffer
);
163 m_pHostShim
->SetMimeType(mimeType
);
165 // error out if we don't have an application or container
166 if (!IsValidMimeType(mimeType
))
171 // Note: Execute() triggers Watson on any failure.
172 m_pHostShim
->Execute();
179 //******************************************************************************
181 // CPersistFile::IsDirty()
183 //******************************************************************************
185 STDMETHODIMP
CPersistFile::IsDirty()
190 //******************************************************************************
192 // CPersistFile::GetCurFile()
194 //******************************************************************************
196 STDMETHODIMP
CPersistFile::GetCurFile(__out LPOLESTR
*ppwszOut
)